package ltd.jdsoft.cute.httpclient.config;

import ltd.jdsoft.cute.common.util.PropertyUtil;

/**
 * httpclient的相关配置，如果未配置，使用默认值
 * 
 * @author zhengzhq
 *
 */
public class HttpClientConfig {

  // 整个httpclient连接池的最大连接数
  private static int maxConnection = PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
      "httpclient.max.connection", Integer.class, 100);
  // 每个路由支持的最大连接数，所有路由的连接数加起来不会超过maxConnection
  private static int maxConnectionPerRoute =
      PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
          "httpclient.max.connection.perroute", Integer.class, 50);
  // 失败重试次数
  private static int retryTimes = PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
      "httpclient.retry.times", Integer.class, 3);
  // 从池子中请求连接的超时时间，应当只有在池子中连接用完等待获取的时候才会出现
  private static int connectionRequestTimeout =
      PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
          "httpclient.connection.request.timeout", Integer.class, 3000);
  // 和对方服务器建立HTTP连接的超时时间
  private static int connectionTimeout =
      PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
          "httpclient.connection.timeout", Integer.class, 30000);
  // 和对方服务器通讯时的超时时间
  private static int socketTimeout = PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
      "httpclient.socket.timeout", Integer.class, 30000);
  // 连接空闲时间
  private static int connectionIdleTime =
      PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
          "httpclient.idleconnection.time", Integer.class, 60000);
  // 定时检测连接的cron表达式
  private static String connectionMgrCronExpression =
      PropertyUtil.getConfig(PropertyUtil.CUTE_DEFAULT_CONFIGURATION,
          "httpclient.connectionmgr.cron.expression", String.class, "0/30 * * * * *");

  public static int getMaxConnection() {
    return maxConnection;
  }

  public static int getMaxConnectionPerRoute() {
    return maxConnectionPerRoute;
  }

  public static int getRetryTimes() {
    return retryTimes;
  }

  public static int getConnectionRequestTimeout() {
    return connectionRequestTimeout;
  }

  public static int getConnectionTimeout() {
    return connectionTimeout;
  }

  public static int getSocketTimeout() {
    return socketTimeout;
  }

  public static int getConnectionIdleTime() {
    return connectionIdleTime;
  }

  public static String getConnectionMgrCronExpression() {
    return connectionMgrCronExpression;
  }
}
